﻿''' <summary>
''' CRUD by default is Disable except when de ControlCD is not define. CRUD is enable
''' </summary>
''' <remarks>Make sure to configure your metacontrol Property</remarks>
Public Class MetaQueryAccess
    Public Property AllowCreate As Boolean = False
    Public Property AllowRead As Short = 0
    Public Property AllowUpdate As Boolean = False
    Public Property AllowDelete As Boolean = False
    Public Property ControlCd As String

    Public Sub New()
    End Sub

    Public Sub New(ByVal controlCd As String)
        AssignSecurity(controlCd)
    End Sub

    Public Sub AssignSecurity(ByVal controlCd As String)
        Dim drow As DataRow

        Using dataView As DataView = Base.AppManager.GetControlSecurity(controlCd, "METAQ")
            If dataView IsNot Nothing AndAlso dataView.Count > 0 Then
                Me.ControlCd = controlCd

                For i As Integer = 0 To dataView.Count - 1
                    drow = dataView.Item(i).Row
                    Select Case drow("Property").ToString
                        Case "AllowCreate"
                            AllowCreate = CBool(drow("Value"))
                        Case "AllowRead"
                            AllowRead = CShort(drow("Value"))
                        Case "AllowUpdate"
                            AllowUpdate = CBool(drow("Value"))
                        Case "AllowDelete"
                            AllowDelete = CBool(drow("Value"))
                        Case Else
                    End Select
                Next
            Else
                AllowRead = CShort(True)
                AllowCreate = True
                AllowUpdate = True
                AllowDelete = True
            End If

        End Using
    End Sub
End Class

